<template>
	<view class="u-page">
		<view class="header"></view>
		<view class="content">
			<view class="label-title">
				<view class="title">提现到微信账户</view>
			</view>
			<view class="balance">
				<view class="balanceLab">余额</view>
				<view class="price">
					<view class="num">￥{{datas.balance + datas.wallet}}</view>
					<view class="tips">
						<view class="tpistitle">可提现金额：￥{{datas.wallet}} </view><view><image src="../../../static/icon/tips.png" mode=""></image></view>
					</view>
				</view>
				<view class="lable-info">提现金额</view>
				<view class="withdrawal"><view class="symbol">￥</view><view class="input"><input type="number" @input="onKeyInput"  placeholder="输入提现金额" /></view></view>
				
			</view>
			<view class="submit">
				<button type="warn" v-if="butstatus == true && wallet==false" @click="submit()">确认提现</button>
				<button type="default" v-else>确认提现</button>
				<view class="subrule" v-if="rule !=''">{{rule}}</view>
			</view>
			<view class="rule-w">
				<view class="rulelab">提现规则</view>
				<view class="ruleContent">
					1、每周仅可申请一次提现，申请提现经平台审核后，48小时内入账微信零钱
					2、每次提现额度小于或等于500元
					<!--  -->
				</view>
			</view>
			
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pid:'',
				lists: [],
				userData:"",
				datas:'',
				inputValue:'',
				butstatus:false,
				wallet:false,
				rule:"",
			}
		},
		onLoad() {
			let user = uni.getStorageSync('userData')
			this.userData = user
			this.userinfo();
			
		},
		methods: {
			onKeyInput: function(event) {
				let inputValue = event.target.value
				if(inputValue <= this.datas.wallet && inputValue < 500){
					this.inputValue = inputValue
					this.butstatus = true
				}else{
					this.butstatus = false
				}
			},
			goback(){
				uni.navigateBack({
					delta: 1
				})
			},
			async userinfo(){
				const users = await this.GQL({
					"operationName": "allSlUsers",
					"query": "query allSlUsers($filter: SlUserFilter) { allSlUsers(filter:$filter) { nodes {balance uid wallet phone} } }",
					"variables": {"filter": {"uid":{"equalTo":uni.getStorageSync('userData').uid}}}
				})
				if(users.data.allSlUsers.nodes !=''){
					
					this.datas = users.data.allSlUsers.nodes[0]
				}
				//查询这几天是否提现过
				// let time = 
				 var date = new Date();
				var year = date.getFullYear();
				var month = date.getMonth() + 1;
				var strDate = date.getDate() - 2;
				var date1 =year+'-'+month+'-'+strDate+' 00:00:00'
				console.log('1---',date1);
				
				
				const wallet = await this.GQL({
					"operationName": "allSlUserWithdrawals",
					"query": "query allSlUserWithdrawals($filter: SlUserWithdrawalFilter) { allSlUserWithdrawals(filter:$filter) { nodes { id uid } } }",
					"variables": { "filter": { "createtime": { "greaterThanOrEqualTo": date1 } } }
				})
				if(wallet.data.allSlUserWithdrawals.nodes !=''){
					this.rule = "您在2天内有提现申请"
					this.wallet = true
				}else{
					this.rule  = '';
					this.wallet = false
				}
				
				
				console.log('user',users)
			},
			async submit(){
				const data = {
					"uid":this.userData.uid,
					'price':parseFloat(this.inputValue),
					'phone':this.datas.phone,
					'account':this.datas.phone,
					'time':JSON.stringify(Date.parse(new Date()))
				}
				const  Withdrawal= await this.GQL({
					"operationName": "createSlUserWithdrawal",
					"query": "mutation createSlUserWithdrawal($input: CreateSlUserWithdrawalInput!) { createSlUserWithdrawal(input: $input) { slUserWithdrawal { id } } }",
					"variables": {"input":{"slUserWithdrawal":data}}
				})
				if(Withdrawal.data.createSlUserWithdrawal.slUserWithdrawal.nodes !=''){
					uni.showModal({
						title: '提示',
						content: '提交成功，等待后台审核。',
						success: function (res) {
							uni.reLaunch({
								url:'/pages/user/wallet/withdrawal'
							})
						}
					});
					
				}
			}
			
		}
	}
</script>

<style lang="scss">
.u-page{
		background-color: #FBFCFE;
	}
	 .header{
	 	width: 100%;
	 	height: 200px;
	 	/* color: #FFFFFF; */
	 	background: linear-gradient(#C7171E, #f0f2f5); /* 标准的语法 */
	 	
	 }
	.content{
		position: relative;
		top: -200px;
		background-color: #FFFFFF;
		border-radius: 5px;
		margin: 15px;
		.label-title{
			height: 50px;
			background: #F9F9F9;
			border-radius: 5px 5px 0px 0px;
			border: 1px solid #EAEAEA;
			.title{
				font-size: 15px;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #161E3E;
				line-height: 16px;
				margin: 20px 0px 14px 17px;
			}
		
		}
		.balanceLab{
			font-size: 18px;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #767B8D;
			line-height: 16px;
			margin: 30px 0px 0px 20px;
		}
		.price{
			display: flex;
			margin: 20px 0px 0px 20px;
			.num{
				padding: 10px 20px 0px 0px;
				font-size: 24px;
				font-family: PingFangSC-Semibold, PingFang SC;
				font-weight: 600;
				color: #767B8D;
				line-height: 16px;
			}
		}
		
		.tips{
			width: 173px;
			height: 30px;
			display: flex;
			background: #FFE1E2;
			.tpistitle{
				font-size: 15px;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #C7171E;
				line-height: 12px;
				padding: 10px 0px 10px 5px;
			}
			border-radius: 15px;
			border: 1px solid #FFB4B7;
			
			image{
				padding: 10px;
				width: 14px;
				height: 14px;
			}
		}
		.lable-info{
			margin: 50px 0px 0px 20px;
			font-size: 15px;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #161E3E;
			line-height: 16px;
		}
		.withdrawal{
			    display: flex;
			    margin: 20px 20px 0px 20px;
			    font-size: 15px;
			    font-family: PingFangSC-Regular, PingFang SC;
			    font-weight: 400;
			    color: #9BA7C1;
			    line-height: 16px;
			    border-bottom: 1px solid #D7D7D7;
				.symbol{
					padding: 4px 0px;
				}
				.input{
					font-size: 15px;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #9BA7C1;
					line-height: 16px;
					padding: 0px 0px 10px 5px;
				}
		}
		.submit{
			margin: 20px 17px;
		}
		.subrule{
			padding: 10px 0px;
			text-align: left;
			font-size: 11px;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #9BA7C1;
			line-height: 18px;
		}
		.rule-w{
			margin: 30px 0px 0px 20px;
			.rulelab{
				font-size: 15px;
				font-family: PingFangSC-Medium, PingFang SC;
				font-weight: 500;
				color: #161E3E;
				line-height: 16px;
			}
			.ruleContent{
				padding: 10px 0px;
				text-align: left;
				font-size: 11px;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #9BA7C1;
				line-height: 18px;
			}
		}
	}
	
</style>